.btn-toolbar
  #repo-stars.pull-right
    = link_to toggle_star_repository_path(@repository), method: :post,
      class: 'btn btn-primary btn-xs', remote: true, id: 'toggle_star',
      data: {placement: 'bottom', toggle: 'tooltip'},
      title: (@repository.starred_by?(current_user) ? 'Unstar repository' : 'Star repository')
      do
        - if @repository.starred_by?(current_user)
          i.fa.fa-star
        - else
          i.fa.fa-star-o
        span#star-counter.badge
          = @repository.stars.count
  - if can_destroy?(@repository)
    #remove-repo.pull-right
      button.remove-repo.btn-x.btn-edit-role.btn.btn-link.btn-xs[
        data-placement="left"
        data-toggle="popover"
        data-title="Please confirm"
        data-content="<p>Are you sure you want to remove this \
        image?</p><a class='btn btn-default'>No</a> <a class='btn \
        btn-primary' data-method='delete' \
        href='#{url_for(@repository)}'>Yes</a>"
        data-html="true"
        role="button"
        title="Delete image"]
        .fa.fa-trash.space-xs-sides
        ' Delete image
.panel.panel-default
  .panel-heading
    .row
      .col-xs-6
        h5
          = link_to @repository.namespace.clean_name, @repository.namespace
          | /
          = @repository.name
      .col-xs-6.text-right
        - if can_push?(@repository.namespace)
          .circle-label.permissions-label.circle-label-sm[data-placement="left"
            data-toggle="popover"
            data-container=".panel-heading"
            data-content="You can push images"
            data-original-title="What can I do?"
            tabindex="0" data-html="true"]
              i.fa.fa-arrow-up
              ' Push
        - if can_pull?(@repository.namespace)
          .circle-label.permissions-label.circle-label-sm[data-placement="left"
            data-toggle="popover"
            data-container=".panel-heading"
            data-content="You can pull images"
            data-original-title="What can I do?"
            tabindex="0" data-html="true"]
            i.fa.fa-arrow-down
            ' Pull
        - if owner?(@repository.namespace)
          .circle-label.permissions-label.circle-label-sm[data-placement="left"
            data-toggle="popover"
            data-container=".panel-heading"
            data-content="You are an owner of this repository"
            data-original-title="What's my role?"
            tabindex="0" data-html="true"]
            i.fa.fa-male
            ' Owner
        - elsif contributor?(@repository.namespace)
          .circle-label.permissions-label.circle-label-sm[data-placement="left"
            data-toggle="popover"
            data-container=".panel-heading"
            data-content="You are a contributor in this repository"
            data-original-title="What's my role?"
            tabindex="0" data-html="true"]
            i.fa.fa-exchange
            ' Contr.
        - elsif viewer?(@repository.namespace)
          .circle-label.permissions-label.circle-label-sm[data-placement="left"
            data-toggle="popover"
            data-container=".panel-heading"
            data-content="You are a viewer in this repository"
            data-original-title="What's my role?"
            tabindex="0" data-html="true"]
            i.fa.fa-eye
            ' Viewer


  .panel-body
    .table-responsive.tags
      table.table.table-stripped.table-hover
        col.col-40
        col.col-20
        col.col-15
        col.col-20
        - if can_destroy?(@repository)
          col.col-5
        thead
          tr
            th Tag
            th Author
            th Image
            th Pushed at
            - if APP_CONFIG.enabled?("delete")
              th
        tbody
          - @tags.each do |tag|
            - if tag.first.digest.blank?
              - tag.each do |t|
                tr
                  td
                    .label.label-success
                      = t.name
                  td= tag.first.owner
                  td
                    - if tag.first.image_id.blank?
                      = "-"
                    - else
                      span[title="sha256:#{tag.first.image_id}"]
                        = tag.first.image_id[0, 12]
                  td= tag.first.updated_at
            - else
              tr
                td
                  - tag.each do |t|
                    .label.label-success
                      = t.name
                td= tag.first.owner
                td
                  - if tag.first.image_id.blank?
                    = "-"
                  - else
                    span[title="sha256:#{tag.first.image_id}"]
                      = tag.first.image_id[0, 12]
                td= tag.first.updated_at

                - if can_destroy?(@repository)
                  td
                    button.remove-tag.fa.fa-lg.fa-trash-o.btn-x.btn-edit-role.btn.btn-link[
                      data-placement="left"
                      data-toggle="popover"
                      data-title="Please confirm"
                      data-content="<p>Are you sure you want to remove this \
                      tag?</p><a class='btn btn-default'>No</a> <a class='btn \
                      btn-primary' data-method='delete' \
                      href='#{url_for(tag.first)}'>Yes</a>"
                      data-html="true"
                      role="button"
                      title="Delete tag"]


#write_comment_form.collapse
  = form_for [@repository, @repository.comments.build], remote: true, html: {id: 'new-comment-form', class: 'form-horizontal', role: 'form'} do |f|
    .form-group
      = f.label :comment, {class: 'control-label col-md-2'}
      .col-md-7
        = f.text_area(:body, class: 'form-control fixed-size', required: false, placeholder: "Please write a comment.")
    .form-group
      .col-md-offset-2.col-md-7
        = f.submit('Add', class: 'btn btn-primary')

.panel.panel-default
  .panel-heading.clearfix
    .row
      .col-sm-6
        h5
          span class="number_of_comments badge"
            = @repository.comments.count
          span class="comment_string"
            - if @repository.comments.count == 1
              |  Comment
            - else
              |  Comments
      .col-sm-6.text-right
        a#write_comment_repository_btn.btn.btn-xs.btn-link.js-toggle-button role="button"
          i.fa.fa-comment
          | Write a comment

  #comments.panel-body.panel-no-side-padding
    .container-full
      - if @repository_comments.empty?
        .no-comments-found
          ' Nobody has left a comment yet.
      - else
        - @repository_comments.each do |comment|
          = render(comment)
